package org.nowcoder.leetcode.hashTable;

/**
 * Title  : 447. Number of Boomerangs
 * Source : https://leetcode.cn/problems/number-of-boomerangs/
 * Author : XrazYang
 * Date   : 2023-08-10
 */
public class LeetCode_447 {
    public int numberOfBoomerangs(int[][] points) {
        //边界条件
        if (points.length < 3) {
            return 0;
        }

        //朴素解法： 居然也ac ...
        int count = 0;
        for (int i = 0; i < points.length; i++) {
            int x1 = points[i][0];
            int y1 = points[i][1];
            for (int j = 0; j < points.length; j++) {
                if (i != j) {
                    int x2 = points[j][0];
                    int y2 = points[j][1];
                    int d1 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
                    for (int k = 0; k < points.length; k++) {
                        if (j != k) {
                            int x = points[k][0];
                            int y = points[k][1];
                            int d2 = (x - x1) * (x - x1) + (y - y1) * (y - y1);
                            if (d1 == d2) {
                                count++;
                            }
                        }
                    }
                }
            }
        }
        return count;
    }
}
